<template>
  <div class="app-container">
    <el-card>
      <!--工具栏-->
      <div class="head-container">
         <eHeader :permission="permission"/>
        <crudOperation :permission="permission" />
      </div>
      <!--工具栏-->

      <!--表单组件-->

      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="applicant" label="申请人"/>
        <el-table-column prop="phoneNum" label="联系手机"/>
        <el-table-column prop="email" label="邮箱"/>
        <el-table-column prop="jobName" label="职位名称"/>
        <el-table-column prop="status" label="面试状态">
          <template slot-scope="scope">
            <el-button v-if ="scope.row.status === 0" type="primary" size="mini">未开始</el-button>
            <el-button v-else-if ="scope.row.status === 1"type="success" size="mini">待面试</el-button>
            <el-button v-else-if ="scope.row.status === 2"type="success" size="mini">通过啦</el-button>
            <el-button v-else ="scope.row.status === 3"type="warning" size="mini">拒绝啦</el-button>
          </template>
        </el-table-column>
        <el-table-column  label="操作" width="300px" align="center">
          <template slot-scope="scope">
            <!--<udOperation
              :data="scope.row"
              :permission="permission"
            />-->
            <!--<el-button type="primary" size="mini">简历</el-button>-->
            <el-button v-if="scope.row.status === 0" @click="showInterview(scope.row)" type="primary" size="mini">约面</el-button>
            <el-button v-if="scope.row.status === 1" @click="pass(scope.row)" type="success" size="mini">
              通过
            </el-button>
            <el-button v-if="scope.row.status === 1" @click="reject(scope.row)" type="danger" size="mini">
              拒绝
            </el-button>
          </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
      <pagination />
    </el-card>

    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="cancelInterview"
      :visible="visibleInterview"
      title="约面试"
      width="500px"
    >
      <el-form ref="form" :model="form" size="small" label-width="80px">

        <el-form-item label="面试时间" prop="time">
          <el-date-picker
            type="datetime"
            v-model="form.time"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 370px;"
          />
        </el-form-item>

        <el-form-item label="面试地点" prop="address">
          <el-input v-model="form.address" style="width: 370px;"/>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" style="width: 370px;"/>
        </el-form-item>

      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button type="text" @click="cancelInterview">取消
        </el-button>
        <el-button
          type="primary"
          @click="submitInterview"
        >
          确认
        </el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import crudInterview, {edit} from '@/api/ceamInterview'
import {getStudentList} from '../../../api/ceamStudent'
import eHeader from './header'
import CRUD, { presenter} from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import udOperation from '@crud/UD.operation'

// crud交由presenter持有
const crud = CRUD({
  title: '面试管理',
  url: 'api/interview',
  sort: ['sort,asc', 'id,desc'],
  crudMethod: { ...crudInterview }
})

export default {
  components: { eHeader, crudOperation, pagination, udOperation },
  mixins: [presenter(crud)],
  data() {
    return {
      delLoading: false,
      studentList: [],
      visibleInterview: false,
      form: {},
      permission: {
        add: ['admin', 'results:add'],
        edit: ['admin', 'results:edit'],
        del: ['admin', 'results:del']
      }
    }
  },
  created() {
    this.$nextTick(() => {
      //this.init()
    })
  },
  methods: {
    checkPermission,
    cancelInterview() {
      this.visibleInterview = false;
    },
    showInterview(data) {
      this.form = data;
      this.visibleInterview = true;
    },
    submitInterview() {
      this.form.status = 1;
      edit(this.form).then(res => {
        this.visibleInterview = false;
        this.$message({
          message: '成功',
          type: 'success'
        });
      }).catch(error => {
        this.$message({
          message: '失败',
          type: 'warning'
        });
      })
    },
    pass(data) {
      data.status = 2;
      edit(data).then(res => {
        this.visibleInterview = false;
        this.$message({
          message: '成功',
          type: 'success'
        });
      }).catch(error => {
        this.$message({
          message: '失败',
          type: 'warning'
        });
      })
    },
    reject(data) {
      data.status = 3;
      edit(data).then(res => {
        this.visibleInterview = false;
        this.$message({
          message: '成功',
          type: 'success'
        });
      }).catch(error => {
        this.$message({
          message: '失败',
          type: 'warning'
        });
      })
    }
  }
}
</script>

<style scoped>

</style>
